export var dataUrlToBlob = function dataUrlToBlob(dataUrl) {
  var _array = dataUrl.split(',');

  var _mimeType = _array[0].match(/:(.*?);/)[1];

  var _bytes = window.atob(_array[1]);

  var _length = _bytes.length;

  var _uint8Array = new Uint8Array(_length);

  while (_length) {
    _length -= 1;
    _uint8Array[_length] = _bytes.charCodeAt(_length);
  }

  return new Blob([_uint8Array], {
    type: _mimeType
  });
};
export var dataUrlToBase64 = function dataUrlToBase64(dataUrl) {
  var _array = dataUrl.split(',');

  var base64 = _array[1];
  return base64;
};
export var fileToDataUrl = function fileToDataUrl(file, callback) {
  var _fileReader = new FileReader();

  _fileReader.onload = function (event) {
    var __fileReader = event.target;
    callback(__fileReader.result);
  };

  _fileReader.readAsDataURL(file);
};
/**
 * 文件选择
 *
 * @param {function} complete 回调事件
 */

var element = null;
export var filePicker = function filePicker(callback, option) {
  element = document.createElement('input');
  element.setAttribute('type', 'file');

  var _ref = option || {},
      _ref$accept = _ref.accept,
      accept = _ref$accept === void 0 ? '*/*' : _ref$accept,
      capture = _ref.capture,
      multiple = _ref.multiple;

  element.setAttribute('accept', accept);

  if (capture) {
    element.setAttribute('capture', capture);
  }

  if (multiple) {
    element.setAttribute('multiple', 'multiple');
  }

  element.style.display = 'none';
  element.addEventListener('change', function (change_event) {
    element = null;
    var _element = change_event.target;

    if (_element.value) {
      var files = _element.files;
      var fileObjs = [];

      for (var i = 0, length = files.length; i < length; i += 1) {
        var file = files[i];
        fileObjs.push({
          file: file
        });
      }

      callback(fileObjs);
    }
  }, true);
  element.click();
};